package com.eedi.framework.oauth2.framework.security;

import com.eedi.framework.oauth2.dal.dataobject.SysOAuth2AccessTokenDO;
import com.eedi.framework.oauth2.service.SysOAuth2TokenService;
import com.eedi.framework.security.core.LoginUser;
import com.eedi.framework.security.core.service.SysOauth2TokenApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class SysOauth2TokenAPIImpl  implements SysOauth2TokenApi {
    @Resource
    SysOAuth2TokenService sysOAuth2TokenService;
    @Override
    public LoginUser checkAccessToken(String s) {
        SysOAuth2AccessTokenDO token = sysOAuth2TokenService.checkAccessToken(s);
        if (token != null) {
          return   new LoginUser().setUserId(token.getSysUserId()).setUserType(token.getSysUserType())
                    .setSysTenantId(token.getSysTenantId()).setScopes(token.getScopes());
        }
        return null;
    }
}
